package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/category")
//分类相关接口
public class CategoryController {
    @Autowired
    private CategoryService categoryService;
    //新增菜品分类,套餐分类
    @PostMapping
    public Result addCategory(@RequestBody Category category){
        System.out.println(category);
        categoryService.addCategory(category);
        return Result.success();
    }
    //菜品分页查询
    @GetMapping("/page")
    public Result selectCategory(CategoryPageQueryDTO categoryPageQueryDTO){
        PageResult pageResult = categoryService.selectCategory(categoryPageQueryDTO);
        return Result.success(pageResult);
    }
    //根据Id删除分类
    @DeleteMapping
    public Result deleteCategory(Integer id){
        categoryService.delectCategory(id);
        return Result.success();
    }
    //根据id查询(数据回显)
    @GetMapping
    public Result selectById(Integer id){
        List<Category> categories = categoryService.selectById(id);
        return Result.success(categories);
    }
    //根据id修改
    @PutMapping
    public Result putById(@RequestBody Category category){
        categoryService.putById(category);
        return Result.success();
    }
    //根据类型查询分类
    @GetMapping("/list")
    public Result selectType(Category category){
        List<Category> categories = categoryService.selectType(category);
        return Result.success(categories);
    }
}
